﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据表 GYK_41_CY_TecGXData 对应的数据应用功能类。
	/// </summary>
	public class GYK_41_CY_TecGXDataApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IGYK_41_CY_TecGXDataRepository service = new GYK_41_CY_TecGXDataRepository();

        public List<GYK_41_CY_TecGXDataEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<GYK_41_CY_TecGXDataEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.ProcessID == keyword);
            }
            return service.FindList(expression, pagination);
        }

        public GYK_41_CY_TecGXDataEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.ProcessID == keyValue);
        }

        public void SubmitForm(GYK_41_CY_TecGXDataEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.FCreateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FCreateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FCreateTime = DateTime.Now.ToString("HH:mm:ss");
                service.Update(entity);
            }
            else
            {
                entity.ProcessID = Common.GuId();
                entity.UseUnit = UseUnit;
                entity.FCreateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FCreateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FCreateTime = DateTime.Now.ToString("HH:mm:ss");
                entity.FUpdateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FUpdateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FUpdateTime = DateTime.Now.ToString("HH:mm:ss");
                service.Insert(entity);
            }
        }
        public GYK_41_CY_TecGXDataEntity GetItem(string FProductionNO, string FProCompanyNO, string FWorkshop, string ProcessNO)
        {
            var expression = ExtLinq.True<GYK_41_CY_TecGXDataEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            expression = expression.And(t => t.FProductionNO == FProductionNO);
            expression = expression.And(t => t.FProCompanyNO == FProCompanyNO);
            expression = expression.And(t => t.FWorkshop == FWorkshop);
            expression = expression.And(t => t.ProcessNO == ProcessNO);
            return service.FindEntity(expression);
        }
    }
}